extends ItemList

signal select_map

var map_scene : PackedScene
var map_instance

func _on_MapList_item_selected(index):
	var item = get_item_text(index)
	if typeof(item) == TYPE_STRING:
		var selected_map: String = "res://Maps/" + item + ".tscn"
		map_scene = load(selected_map)
		if map_scene:
			get_node("/root/MapViewer/VBoxContainer/ButtonBarHbox/PlayButton").disabled = false
			map_instance = map_scene.instance()
			var vp = get_parent().get_node("ViewportContainer/Viewport")
			for c in vp.get_children():
				c.queue_free()
			vp.add_child(map_instance)
			emit_signal("select_map", selected_map)
